package com.jhj.common.view;

import org.springframework.web.servlet.view.AbstractUrlBasedView;
import org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver;

import java.util.Map;

/**
 * Velocity渲染
 * 
 * @author GaoXiang Date: 2014-7-17
 */
public class JhjVelocityLayoutViewResolver extends VelocityLayoutViewResolver {
    
    /**
     * 存放公用url的map
     */
    private Map<String, String> velocityUrl;
    
    /**
     * 页面工具类
     */
    private Map<String, Object> velocityTools;
    
    protected Class<?> requiredViewClass() {
        return JhjVelocityLayoutView.class;
    }
    
    /**
     * 构建视图
     * 
     * @param viewName
     * @return
     * @throws Exception
     */
    protected AbstractUrlBasedView buildView(String viewName) throws Exception {
        JhjVelocityLayoutView view = (JhjVelocityLayoutView) super.buildView(viewName);
        if (this.velocityUrl != null && velocityUrl.size() > 0) {
            view.setVelocityUrl(velocityUrl);
        }
        if (this.velocityTools != null && velocityTools.size() > 0) {
            view.setVelocityTools(velocityTools);
        }
        return view;
    }
    
    public void setVelocityUrl(Map<String, String> velocityUrl) {
        this.velocityUrl = velocityUrl;
    }
    
    public void setVelocityTools(Map<String, Object> velocityTools) {
        this.velocityTools = velocityTools;
    }
}
